using System;
using System.Windows.Forms;

using DirectShowLib;

namespace Engine.Media
{
    public class Audio : Media
    {
        // Concrete attributes
        private IBasicAudio basicAudio = null;

        // Concrete constructor
        public Audio(String filename, Form form)
        {
            int hr = 0;

            // Have the graph builder construct its the appropriate graph automatically
            this.graphBuilder = (IGraphBuilder) new FilterGraph();

            // Render file
            hr = this.graphBuilder.RenderFile(filename, null);
            DsError.ThrowExceptionForHR(hr);

            // QueryInterface for DirectShow interfaces
            this.mediaControl = (IMediaControl) this.graphBuilder;
            this.mediaEventEx = (IMediaEventEx) this.graphBuilder;
            this.mediaSeeking = (IMediaSeeking) this.graphBuilder;
            this.mediaPosition = (IMediaPosition) this.graphBuilder;

            // Query for audio interfaces
            this.basicAudio = this.graphBuilder as IBasicAudio;

            // Have the graph signal event via window callbacks for performance
            hr = this.mediaEventEx.SetNotifyWindow(form.Handle, WMGraphNotify, IntPtr.Zero);
            DsError.ThrowExceptionForHR(hr);

            // Complete window initialization
            this.currentPlaybackRate = 1.0;
        }
    }
}
